import { Component, OnInit } from '@angular/core';
import { FundInfoService } from './fund-info.service';
import { AppPaginationComponent, PaginationModel } from "../../../../widgets/pagination/pagination.component";
import * as _ from 'lodash';

@Component({
  selector: 'app-fund-info',
  templateUrl: './fund-info.component.html',
  styleUrls: ['./fund-info.component.scss'],
  providers: [FundInfoService]
})
export class FundInfoComponent implements OnInit {
  // 基金信息
  public listFundInfo: any;
  // 产品文档列表
  public dataList = [];
  // 查询分页列表post数据
  public getListPost: any = {
    pageIndex: 1,
    pageSize: 10,
    attachNo:''
  };
  //产品文档分页配置
  public listPageInfo: PaginationModel = {
    currentPageNum: 1,
    pageSize: 10,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };
  constructor(
    public fundInfoService: FundInfoService,
  ) { }

  ngOnInit() {
    this.list();
  }
  // 查询分页列表
  list(pageNum?, pageSize?) {
    let that = this;
    this.getListPost.attachNo = this.listFundInfo.nAttachNo;
    this.getListPost.pageIndex = pageNum ? pageNum : this.listPageInfo.currentPageNum;
    this.getListPost.pageSize = pageSize ? pageSize : this.listPageInfo.pageSize;
    this.fundInfoService.list(this.getListPost).subscribe(data => {
      if (data) {
        that.dataList = data.list;
        that.listPageInfo.currentPageNum = data.pageNum;
        that.listPageInfo.totalPages = data.pages;
        that.listPageInfo.total = data.total;
        that.listPageInfo.startRow = data.startRow;
        that.listPageInfo.endRow = data.endRow;
      }
    });
  }
  // 按选取个数分页
  listpageSizeChange(pageSize: number) {
    if (pageSize !== this.listPageInfo.pageSize) {
      this.listPageInfo.pageSize = pageSize;
      this.list();
    }
  }
  // 页码分页导航
  listPageNavigation(currentPageNum: number) {
    this.listPageInfo.currentPageNum = currentPageNum;
    this.list(this.listPageInfo.currentPageNum, this.listPageInfo.pageSize);
  }
}
